home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
Z4Z4BLD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-08-08
|
10KB
|
355 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: z4z4bld.c
// Title: 9-Digit ZIP Code Directory -- on CD-ROM
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
// This module contains the program entry point for
//
// The code in this module may be written in C++ or C.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
//
//----------------------------------------------------------------------------
#include <z4.h>
//----------------------------------------------------------------------------
// Stack size
//----------------------------------------------------------------------------
#if COMPILER_BORLAND && (OS_DOS || OS_WINDOWS)
unsigned _stklen = 0x4000;
#endif
//----------------------------------------------------------------------------
// Globals
//----------------------------------------------------------------------------
//
// A useless string which is simply embedded in the executable.
//
PSZ __pszCredits__ = "Written by John M Weeder, 1993";
//
// This should contain a program description which will be displayed as
// part of the program's help text.
//
static PCSZ pcszDescription =
"This program compresses a ZIP+4 data file.";
//
// Program command line options
//
static DATACFG dcfg;
static PZ4_PF_TBL pf_tbl = NULL;
static BOOL fCompress = FALSE;
static BOOL fIndex = FALSE;
static BOOL fRecNo = FALSE;
static BOOL fCheck = FALSE;
static BOOL fCrc = FALSE;
static CHAR szConfig[MAX_PATH] = "z4z4";
static BOOL fNoDelete = FALSE;
static BS_CMDOPT acmdopt[] =
{
{ "CHECK", (PVOID)&fCheck, CMDOPT_TRUE, "Validate CRC codes."},
{ "COMPRESS", (PVOID)&fCompress, CMDOPT_TRUE, "Compress data file."},
{ "CRC", (PVOID)&fCrc, CMDOPT_TRUE, "Generate CRC codes."},
{ "INDEX", (PVOID)&fIndex, CMDOPT_TRUE, "Index data file."},
{ "NODELETE", (PVOID)&fNoDelete, CMDOPT_TRUE, "Don't delete old files."},
{ "RECNO", (PVOID)&fRecNo, CMDOPT_TRUE, "Process record count file."},
{ "config", (PVOID)szConfig, CMDOPT_FILESPEC(80), "Configuration file name."},
BS_CMDOPT_NULL,
};
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns:
//----------------------------------------------------------------------------
VOID FN_E Z4Strip(PDATACFG pcfg, PRECID precid, PSZ _FAR_ *apsz, PBYTE pb)
{
static SIZET cPriNoKey;
static SIZET cPriNameKey;
static SIZET cPriName;
static SIZET cPriNoLo;
static SIZET cPriNoHi;
static SIZET cAddonLo;
static SIZET cAddonHi;
static SIZET cSuffix;
static SIZET cSecName;
static SIZET cRecType;
CHAR szPriName[MAX_PRI_NAME+1];
Z4_SUFFIX suffix;
BOOL fOrdinal;
CHAR szPriLo[MAX_PRI_NO+1];
CHAR szPriHi[MAX_PRI_NO+1];
NOTUSED(pb);
NOTUSED(precid);
if (apsz == NULL)
{
cPriNoKey = DataField(pcfg, "pri_no_key");
cPriNameKey = DataField(pcfg, "pri_name_key");
cPriName = DataField(pcfg, "pri_name");
cPriNoLo = DataField(pcfg, "pri_no_lo");
cPriNoHi = DataField(pcfg, "pri_no_hi");
cAddonLo = DataField(pcfg, "addon_lo");
cAddonHi = DataField(pcfg, "addon_hi");
cSuffix = DataField(pcfg, "suffix");
cSecName = DataField(pcfg, "sec_name");
cRecType = DataField(pcfg, "record_type_code");
return ;
}
Z4Clean(apsz[cPriName]);
Z4Clean(apsz[cSuffix]);
Z4Clean(apsz[cSecName]);
Z4Z4CompressRange(apsz[cPriNoHi]);
Z4Z4CompressRange(apsz[cPriNoLo]);
strcpy(szPriLo, apsz[cPriNoLo]);
strcpy(szPriHi, apsz[cPriNoHi]);
if (szPriLo[0] == '-')
szPriLo[0] = '0';
if (szPriHi[0] == '-')
szPriHi[0] = '0';
//
// Standardize the RR default records
//
// if (apsz[cRecType][0] == '1' && apsz[cRecType][1] == '8')
if (apsz[cRecType][0] == 'R') // new code replaces old code above
{
if (memcmp(apsz[cPriNoHi], "0000000000", 10) == 0
&& memcmp(apsz[cPriNoLo], "0000000000", 10) == 0)
{
memset(apsz[cPriNoHi], ' ', 10);
memset(apsz[cPriNoLo], ' ', 10);
szPriLo[0] = '\0';
szPriHi[0] = '\0';
}
}
//
// Handle odd-ball addon's for non-deliverables
//
if ((apsz[cAddonLo][1] == 'N' && apsz[cAddonLo][2] == 'D')
|| (apsz[cAddonLo][2] == 'N' && apsz[cAddonLo][3] == 'D'))
apsz[cAddonLo][0] = '\0';
if ((apsz[cAddonHi][1] == 'N' && apsz[cAddonHi][2] == 'D')
|| (apsz[cAddonHi][2] == 'N' && apsz[cAddonHi][3] == 'D'))
apsz[cAddonHi][0] = '\0';
//
// Do some parsing on the primary name so that the sort key may
// be built. Remove any trailing suffix words and any ordinal suffixes.
//
Z4Z4CompressPriName(apsz[cPriName], szPriName, &suffix, &fOrdinal);
//
// Build the phonetics!
//
if (szPriHi[0] && !szPriLo[0]) {
strcpy(szPriLo, szPriHi);
}
Metaphone(szPriName, (PBYTE)apsz[cPriNameKey], 3);
AlNumKey(Z4Z4CompressRange(szPriLo), (PBYTE)apsz[cPriNoKey], 3);
return;
}
//----------------------------------------------------------------------------
// Description: //added description...builds the z4z4.inp,dld, and dlx files
// Parameters:
// Returns:
//----------------------------------------------------------------------------
BOOL FN_E Compress(void)
{
LONG l;
CHAR szWork[MAX_PATH];
CHAR szFinance[MAX_PATH];
if (!Z4PofCreate(&pf_tbl, Z4_PF_TBL_WORK_MAX)
|| !Z4PofRead(pf_tbl, Z4_PF_TBL_WORK))
return FALSE;
if (pf_tbl->lSize == 0)
{
Output("No POF's to process.\n");
return TRUE;
}
strcpy(szWork, "z4z4.inp");
if (!FnameQualify(szWork, "inp", EnvGet("DATA"), 0))
return FALSE;
if (FnameIsFile(szWork))
if (!FnameDelete(szWork))
return FALSE;
#if OS_DOS
Output("\nPress escape to abort...\n\n");
#endif
Output("Combining finance records:\n");
for (l = 0; l < pf_tbl->lSize; ++l)
{
#if OS_DOS
while (KbdReady())
if (KbdChar() == '\x1B')
{
Output("\nAborted!\n");
return FALSE;
}
#endif
strb2a(pf_tbl->abPof[(SIZET)l], MAX_FINANCE_BCD, szFinance, MAX_FINANCE, TRUE);
szFinance[MAX_FINANCE] = '\0';
Output(" %s\n", szFinance);
if (!FnameQualify(szFinance, "inp", EnvGet("DATA"), 0))
return FALSE;
if (!CopyFile(szFinance, szWork, FCOPY_APPEND|FCOPY_NO_DATE, NULL))
return FALSE;
if (!fNoDelete)
if (!FnameDelete(szFinance))
return FALSE;
}
if (!DataConfigFiles(&dcfg, szWork))
return FALSE;
if (!DataStrip(&dcfg, Z4Strip))
{
Output("Failed stripping fixed length records.\n");
return FALSE;
}
if (!fNoDelete)
{
if (FnameIsFile(dcfg.szInput))
if (!FnameDelete(dcfg.szInput))
return FALSE;
}
if (!DataSort(&dcfg))
{
Output("Failed sorting delimited data file.\n");
return FALSE;
}
if (!DataCompress(&dcfg, Z4Z4Compress, DAC_XREF|DAC_RECNO))
{
Output("Failed compressing data file.\n");
return FALSE;
}
if (!fNoDelete)
if (!DataDelimitDelete(&dcfg))
{
Output("Failed deleting temporary data files.\n");
return FALSE;
}
Z4PofDelete(pf_tbl, l); // Update work table!
if (!Z4PofWrite(pf_tbl, Z4_PF_TBL_WORK))
return FALSE;
return TRUE;
}
//----------------------------------------------------------------------------
// Description: main() - Program entry point
// Parameters: Standard C parameters
// Returns: DOS return code.
//----------------------------------------------------------------------------
int main(int argc, char **argv)
{
static BS_CFG cfg = CFG_DFT;
int retval = 99;
//
// Initialize base library
//
BaseLibraryInitialize(argc, argv, &cfg);
BaseTitle("$Revision: 93.1 $", __DATE__, __TIME__, "9-Digit ZIP Disc ZIP+4 File Build");
if (!BaseTitleHelp(acmdopt, pcszDescription,NULL))
return 99;
DioSetDataPath(getenv("DATA"));
if (!DataConfigRead(szConfig, &dcfg))
{
Output("Failed reading configuration file.\n");
goto ERROR_EXIT;
}
if (fCompress)
{
if (!Compress())
{
Output("Failed compressing delimited data file.\n");
goto ERROR_EXIT;
}
}
if (fCrc)
if (!DioCrc(dcfg.szData, dcfg.szLogical, DFT_ISAM_DATA, NULL))
{
Output("Failed generating CRC codes for data area.\n");
return 99;
}
if (fRecNo)
if (!DataRecNo(&dcfg))
{
Output("Failed generating record number index.\n");
return 99;
}
if (fIndex)
if (!DataIndex(&dcfg, Z4Z4Index))
{
Output("Failed indexing data file.\n");
return 99;
}
if (fCheck)
if (!DioCheck(dcfg.szData))
{
Output("Failed verifying data file.\n");
return 99;
}
retval = 0;
ERROR_EXIT:
Z4PofDestroy(pf_tbl);
DioCloseAll();
return retval;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------